import 'package:flutter/material.dart';
import 'package:riki_login/entity/role_info_entity.dart';

///作者：范玉辉
///创建时间：2021/8/17
///说明：

class StaffLoginEntity {
  //订单用户
  static final int orderUserTypeSelf = 1;

  //亲友团
  static final int orderUserFriend = 0;

  //用户身份
  static const int userTypeOfUser = 0;

  //服务端身份
  static const int userTypeOfService = 1;

  //即使用户又是设计师
  static const int userTypeOfDualIdentity = 2;

  /// 角色身份

  // 主案设计师
  static final int roleDesign = 1;

  // 管理员
  static final int roleAdmin = 10;

  // 量房员
  static const int roleGauge = 12;

  // 客服
  static const int roleButLer = 13;

  // 工人
  static const int roleWorker = 14;

  // 工长
  static const int roleForeman = 15;

  // 管家
  static const int roleHouseKeeper = 17;

  // 木作设计师
  static const int roleWood = 2;

  String? accessToken;
  int? appId;
  int? areaId;
  String? avatar;
  int? cityId;
  int? companyId;
  String? employeeJpushId;
  bool? hasEstate;
  int? id;
  String? jpushId;
  String? name;
  String? phone;
  int? provinceId;
  String? refreshToken;
  int? sex;
  bool? certifyStatus;
  String? tid;
  String? userSign;
  int? userType;
  int? identityState = 2;
  List<RoleInfoEntity>? roleVOList;

  int get getRoleList {
    if (roleVOList == null) {
      return 0;
    }
    return roleVOList?.length ?? 0;
  }

  ///工人:"worker_staff"  管家:"butler"  必填
  ///  工人
//   static const int userTypeWorker = 14;
//   管家
//   static const int userTypeForeman  = 15;
  String getCodeParam() {
    if (roleVOList?.isNotEmpty ?? false) {
      if (roleVOList?.first.type == RoleInfoEntity.userTypeForeman) return "butler";
      if (roleVOList?.first.type == RoleInfoEntity.userTypeWorker) return "worker_staff";
    }
    return "";
  }

  bool get getCertifyStatus {
    if (certifyStatus == null) {
      return true;
    }
    return certifyStatus!;
  }

  StaffLoginEntity({
    this.accessToken,
    this.appId,
    this.areaId,
    this.avatar,
    this.cityId,
    this.companyId,
    this.employeeJpushId,
    this.hasEstate,
    this.id,
    this.jpushId,
    this.name,
    this.phone,
    this.provinceId,
    this.refreshToken,
    this.identityState,
    this.sex,
    this.tid,
    this.userSign,
    this.userType,
    this.roleVOList,
    this.certifyStatus,
  });

  StaffLoginEntity.fromJson(Map<String, dynamic> json) {
    accessToken = json['accessToken'];
    certifyStatus = json['certifyStatus'];
    appId = json['appId'];
    areaId = json['areaId'];
    avatar = json['avatar'];
    cityId = json['cityId'];
    companyId = json['companyId'];
    employeeJpushId = json['employeeJpushId'];
    hasEstate = json['hasEstate'];
    id = json['id'];
    jpushId = json['jpushId'];
    identityState = json['identityState'];
    name = json['name'];
    phone = json['phone'];
    provinceId = json['provinceId'];
    refreshToken = json['refreshToken'];
    sex = json['sex'];
    tid = json['tid'];
    userSign = json['userSign'];
    userType = json['userType'];
    if (json['roleVOList'] != null) {
      roleVOList = <RoleInfoEntity>[];
      json['roleVOList'].forEach((v) {
        roleVOList!.add(new RoleInfoEntity.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['accessToken'] = this.accessToken;
    data['appId'] = this.appId;
    data['areaId'] = this.areaId;
    data['avatar'] = this.avatar;
    data['cityId'] = this.cityId;
    data['certifyStatus'] = this.certifyStatus;
    data['companyId'] = this.companyId;
    data['employeeJpushId'] = this.employeeJpushId;
    data['hasEstate'] = this.hasEstate;
    data['id'] = this.id;
    data['jpushId'] = this.jpushId;
    data['name'] = this.name;
    data['identityState'] = this.identityState;
    data['phone'] = this.phone;
    data['provinceId'] = this.provinceId;
    data['refreshToken'] = this.refreshToken;
    data['sex'] = this.sex;
    data['tid'] = this.tid;
    data['userSign'] = this.userSign;
    data['userType'] = this.userType;
    if (this.roleVOList != null) {
      data['roleVOList'] = this.roleVOList!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
